﻿
Partial Public Class Pending
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        LoadAdvertisements()

    End Sub

    Private Sub LoadAdvertisements()

        Dim advertiserManager As New BLL.AdvertiserManager

        Dim adManager As New BLL.AdvertisementManager

        gvAdvertisements.DataSource = adManager.GetAllPendingAdvertisements()
        gvAdvertisements.DataBind()
    End Sub

    Private Sub gvAdvertisements_SelectedIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSelectEventArgs) Handles gvAdvertisements.SelectedIndexChanging
        Dim advertisementID As Integer = Convert.ToInt32(gvAdvertisements.DataKeys(e.NewSelectedIndex).Values(0))

        Dim manager As New BLL.AdvertisementManager

        Dim ad As Domain.dnc_Advertisement = manager.GetAdvertisementByID(advertisementID)

        ad.Active = True

        ' Get difference
        Dim timeDifference As TimeSpan = Date.Now.Subtract(ad.startDate.Value)

        ad.startDate = ad.startDate.Value.Add(timeDifference)
        ad.EndDate = ad.EndDate.Value.Add(timeDifference)

        'Save

        manager.Update(ad)

        LoadAdvertisements()

    End Sub


End Class